package top.abrsm.util;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import top.abrsm.entity.BaseEntity;

import java.util.*;

public class Framework {


    public static void main ( String[] args ) {
        parseData ();
    }


    public static void parseData () {
        List<String> tables = new ArrayList<> ();
        tables.add ( "address_info" );
        tables.add ( "car_info" );
        tables.add ( "category_info" );
        tables.add ( "comment_info" );
        tables.add ( "file_info" );
        tables.add ( "product_info" );
        tables.add ( "refund_info" );
        tables.add ( "student_info" );
        tables.add ( "order_info" );

        FastAutoGenerator.create ( "jdbc:mysql://112.124.66.251:9999/mall?useSSL=false&nullCatalogMeansCurrent=true", "matao", "Wuzh0nghua" )
                .globalConfig ( builder -> {
                    builder.author ( "WuZH" )               //作者
                            .outputDir ( System.getProperty ( "user.dir" ) + "\\src\\main\\java" )    //输出路径(写到java目录)
                            .enableSwagger ()           //开启swagger
                            .commentDate ( "yyyy-MM-dd" )
                            .fileOverride ();            //开启覆盖之前生成的文件
                } )
                .packageConfig ( builder -> {
                    builder.parent ( "top.abrsm" )
                            .entity ( "entity" )
                            .service ( "service" )
                            .serviceImpl ( "service.impl" )
                            .controller ( "controller" )
                            .mapper ( "mapper" ).xml ( "impl" );
                } )
                .strategyConfig ( builder -> {
                    builder.addInclude ( tables )
                            .addTableSuffix ( "_info" )
                            .serviceBuilder ()
                            .formatServiceFileName ( "I%sService" )
                            .formatServiceImplFileName ( "%sServiceImpl" )
                            .entityBuilder ()
                            .formatFileName ( "%sEntity" )
                            .columnNaming ( NamingStrategy.no_change )
                            .enableLombok ()
                            .idType ( IdType.INPUT )
                            .superClass ( BaseEntity.class )
                            .enableTableFieldAnnotation ()
                            .controllerBuilder ()
                            // 映射路径使用连字符格式，而不是驼峰
                            .formatFileName ( "%sController" )
                            .enableRestStyle ()
                            .mapperBuilder ()
                            //生成通用的resultMap
                            //.enableBaseResultMap ()
                            .superClass ( BaseMapper.class )
                            .formatMapperFileName ( "%sMapper" )
                            .formatXmlFileName ( "%sMapper" )
                            .enableMapperAnnotation ();
                } )
                .templateEngine ( new FreemarkerTemplateEngine () ) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute ();
    }


}
